package com.detu.ivos.user.controller;


import com.detu.ivos.base.response.JsonResult;
import com.detu.ivos.base.response.StatusCode;
import com.detu.ivos.user.pojo.dto.UserLoginParam;
import com.detu.ivos.user.pojo.dto.UserQuery;
import com.detu.ivos.user.pojo.dto.UserSaveParam;
import com.detu.ivos.user.pojo.vo.UserVO;
import com.detu.ivos.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录:userLoginParam={}",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    //新增或者更新用户
    @PostMapping("save")
    public JsonResult saveUser(UserSaveParam userSaveParam){
        log.debug("新增或者更新用户:userLoginParam={}",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult queryUser(UserQuery userQuery){
        log.debug("查询用户:userQuery={}", userQuery);
        List<UserVO> listUser = userService.queryUser(userQuery);
        return  JsonResult.ok(listUser);
    }
    @PostMapping("/update/password/{userId}")
    public JsonResult resetPassword(@PathVariable Long userId){
        log.debug("重置密码userID:",userId);
        userService.resetPassword(userId);
        return JsonResult.ok();
    }

    @PostMapping("/update/password/{userId}/{status}")
    public JsonResult changeStatus(@PathVariable Long userId,@PathVariable String status){
        log.debug("重置状态:",userId,status);
        userService.changeStatus(userId,status);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{userId}")
    public JsonResult deleteUser(@PathVariable Long userId){
        log.debug("被删除用户的userID:",userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }


    @GetMapping("select/audit/{parentId}")
    public JsonResult selectAuditUserList(@PathVariable Long parentId){
        log.debug("查询审批人列表：parentId={}",parentId);
        List<UserVO> list=userService.selectAuditUserList(parentId);
        return JsonResult.ok(list);
    }

}
